﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.LIB;

namespace HYElectricSystemSetting
{
	public partial class CreatDataRows : System.Windows.Forms.Form
	{
		public CreatDataRows(int intOrdouble, List<string> SameList, string LbFtext, string lbStext)
		{
			this.InitializeComponent();
			this.FirstText = LbFtext;
			this.SecondText = lbStext;
			this.SameStr = SameList;
			this.intOrdouble = intOrdouble;
			if (lbStext == "")
			{
				this.lbSecondValue.Visible = false;
				this.tbSecondValue.Visible = false;
			}
		}

		private void CreatDataRows_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.lbFirstValue.Text = this.FirstText + "：";
			this.lbSecondValue.Text = this.SecondText + "：";
		}

		private void btnAddRows_Click(object sender, EventArgs e)
		{
			this.ischeck = true;
			if (this.tbFirstValue.Text.Trim() == "" || (this.tbSecondValue.Text.Trim() == "" && this.SecondText != ""))
			{
				MessageBox.Show("名称或值不能为空！", "盈建科提示");
				this.ischeck = false;
				return;
			}
			using (List<string>.Enumerator enumerator = this.SameStr.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current == this.tbFirstValue.Text)
					{
						MessageBox.Show("此尺寸已存在！", "盈建科提示");
						this.ischeck = false;
						break;
					}
				}
			}
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
		{
			ElectricSystemSettingData.PressIntOrDouble(this.intOrdouble, sender, e);
		}

		private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
		{
			ElectricSystemSettingData.PressIntOrDouble(0, sender, e);
		}

		private void CreatDataRows_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (base.DialogResult == DialogResult.OK && !this.ischeck)
			{
				e.Cancel = true;
			}
		}

		private void tbFirstValue_TextChanged(object sender, EventArgs e)
		{
			string text = this.tbFirstValue.Text;
			if (text.IndexOf('.') != -1)
			{
				this.tbFirstValue.Text = text;
			}
		}

		private void tbSecondValue_TextChanged(object sender, EventArgs e)
		{
			string text = this.tbSecondValue.Text;
			if (text.IndexOf('.') != -1)
			{
				this.tbSecondValue.Text = text;
			}
		}

		private bool ischeck = true;

		private List<string> SameStr = new List<string>();

		private string FirstText;

		private string SecondText;

		private int intOrdouble;
	}
}
